package com.gec.mall.controller;

import com.gec.mall.pojo.PageReq;
import com.gec.mall.pojo.PageResp;
import com.gec.mall.pojo.RespBean;
import com.gec.mall.pojo.TbBrand;
import com.gec.mall.service.BrandService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: li
 * @Date: 2023/1/7
 * @PACKAGE_NAME:com.gec.mall.controller
 * @Project_Name:mall-parent
 * @VERSION: 1.0.0
 */
@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @GetMapping("/getBrandByPage")
    public PageResp findAllBrand(PageReq pageReq){
        PageHelper.startPage(pageReq.getPage(), pageReq.getSize());
        Page<TbBrand> page = (Page<TbBrand>) brandService.findAllBrand();
        PageResp pageResp = new PageResp();
        pageResp.setList(page.getResult());
        pageResp.setTotal(page.getTotal());
        return pageResp;
    }

    @GetMapping("/getAllBrand")
    public RespBean findBrand(){
        return RespBean.ok("..",brandService.findAllBrand());
    }

    @PostMapping("/saveOrUpdateBrand")
    public RespBean saveOrUpdate(@RequestBody TbBrand brand){
        brandService.saveOrUpdateBrand(brand);
        return RespBean.ok("保存成功！");
    }

    @DeleteMapping("/deletePageById/{id}")
    public RespBean deleteById(@PathVariable Long id){
        brandService.deleteBrandById(id);
        return RespBean.ok("删除成功");
    }
}
